
//
//  VisitorLoginView.m
//  coca
//
//  Created by 张帅 on 15/9/27.
//  Copyright © 2015年 ZhangShuai. All rights reserved.
//

#import "VisitorLoginView.h"

@interface VisitorLoginView ()
@property(nonatomic,strong)UIImageView *iconView;

@property(nonatomic,strong)UIImageView *homeView;

@property(nonatomic,strong)UIImageView *maskView;

@property (nonatomic,strong)UILabel *messageLablel;


-(void)startAnimation;

@end
@implementation VisitorLoginView



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        [self setUpUI];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setUpUI];
       
    }
    return self;
}




-(void)setupInfoImageName:(NSString *)imageName message:(NSString *)message{
    
    
    self.messageLablel.text = message;
    
    if (imageName!=nil) {
        self.iconView.image =[UIImage imageNamed:imageName ];
        self.homeView.hidden =YES;
        
        [self sendSubviewToBack:self.maskView];
        
    }else{
    
        [self startAnimation];
    }
    
}


-(void)startAnimation {
    
    CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    anim.toValue = @(M_PI);
    anim.repeatCount = MAXFLOAT;
    anim.duration = 4;
    anim.removedOnCompletion = NO;
    
    [self.iconView.layer addAnimation:anim forKey:nil];
}




- (void)setUpUI{
   
    [self addSubview:self.iconView];
    
    
    [self addSubview:self.maskView];
    [self addSubview:self.homeView];
    
    [self addSubview:self.messageLablel];
    [self addSubview:self.registerButton];
    [self addSubview:self.loginButton];
    
    
    self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
    
    self.homeView.translatesAutoresizingMaskIntoConstraints  =NO;
    
     self.maskView.translatesAutoresizingMaskIntoConstraints = NO;
    self.messageLablel.translatesAutoresizingMaskIntoConstraints =NO;
    self.registerButton.translatesAutoresizingMaskIntoConstraints =NO;
    self.loginButton.translatesAutoresizingMaskIntoConstraints =NO;
    //MARk: iconView 的NSLayoutConstraint
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.iconView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
  
    
    
    //MARk: homeView 的NSLayoutConstraint
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.homeView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
    
    //MARk: messageLablel 的NSLayoutConstraint
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLablel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];


    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLablel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.iconView attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLablel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:200]];
    
    
    // MARK: 注册按钮
    
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.messageLablel attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    
    
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLablel attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:80]];
    
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:40]];
       // MARK: 登录按钮
    
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.messageLablel attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    
    
    [self addConstraint: [NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLablel attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:80]];
    
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:40]];
    
    
    NSArray *cons  = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[v]-0-|" options:NSLayoutFormatDirectionLeftToRight metrics:nil views:@{@"v":self.maskView }];
    
    [self addConstraints:cons];
   
    
    NSArray *con1 =[ NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[v]-(-35)-[re]" options:NSLayoutFormatDirectionMask metrics:nil views:@{@"v":self.maskView,@"re":self.registerButton}];
    [self addConstraints:con1];
//    backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1.0)

    self.backgroundColor = [UIColor colorWithWhite:237.0 / 255 alpha:1.0]
    ;
}




-(UIImageView *)iconView {
 
    if (_iconView==nil) {
        
        _iconView =[[UIImageView alloc]init];
        _iconView.image =[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
        
    }
    return _iconView;
}

-(UIImageView *)homeView{
    if (_homeView==nil) {
        _homeView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeView;

}


-(UILabel *)messageLablel{

    if (_messageLablel==nil) {
        
       _messageLablel =[[UILabel alloc] init];
        _messageLablel.text =@"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
        _messageLablel.textColor = [UIColor orangeColor];
        _messageLablel.font= [UIFont systemFontOfSize:14];
        _messageLablel.numberOfLines = 0;
    }
    return _messageLablel;
}


-(UIButton *)loginButton{
    if (_loginButton==nil) {
       
        self.loginButton = [[UIButton alloc] init];
    
    
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
       
        [_loginButton setTitleColor:[UIColor orangeColor] forState:(UIControlStateNormal)];
        [_loginButton setTitleColor:[UIColor darkGrayColor] forState:(UIControlStateHighlighted)];
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:(UIControlStateNormal)];
    
    }
    return _loginButton;
}




-(UIButton *)registerButton {
    if (_registerButton ==nil) {
        
        _registerButton =[[UIButton alloc] init];
        
        [_registerButton setTitle:@"注册" forState:(UIControlStateNormal)];
        [_registerButton setTitleColor:[UIColor orangeColor] forState:(UIControlStateNormal)];
        [_registerButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:(UIControlStateNormal)];
//     
//        [_registerButton addTarget:self action:@selector(registerButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _registerButton;
}





-(UIImageView *)maskView{
    if (_maskView==nil) {
        _maskView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
        
    }
    return _maskView;
}


@end
